文章目录
  1. 1. gitlab ssh配置问题
    1. 1.1. 背景
    2. 1.2. 问题一 本地私钥找不到
    3. 1.3. 问题2 不支持密码认证
    4. 1.4. 步骤3 设置ssh端口
    5. 1.5. 参考链接

gitlab ssh配置问题

背景

通过docker-compose部署了gitlab,ssh端口映射为 822->22。已经按照官方文档,本地用户名下的.ssh文件夹下生成了公钥和私钥对,在gitlab添加了公钥。通过http方式可以正常clone项目。但是 ssh -Tv 10.215.136.231 882 提示错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
ssh -Tv 10.215.136.231 882
OpenSSH_7.5p1, OpenSSL 1.0.2k 26 Jan 2017
debug1: Reading configuration data /c/Users/*/.ssh/config
debug1: /c/Users/*/.ssh/config line 1: Applying options for 10.215.136.231
/c/Users/*/.ssh/config line 3: Unsupported option "rsaauthentication"
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.215.136.231 [10.215.136.231] port 822.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.215.136.231:822 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:D3soSmSlP1BUILvtJaratVUOUMsO9oxGvLFm0A3yuv4
debug1: Host '[10.215.136.231]:822' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/*/.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: id_rsa
no such identity: id_rsa: No such file or directory
debug1: No more authentication methods to try.
Permission denied (publickey).

问题一 本地私钥找不到

1
2
3
4
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.215.136.231 [10.215.136.231] port 822.
debug1: Connection established.
debug1: key_load_public: No such file or directory

参考官方文档,本地添加~/.ssh/config文件,文件内容如下:

1
2
3
4
5
6
Host 10.215.136.231
Hostname 10.215.136.231
RSAAuthentication yes
User git
Port 822
IdentityFile id_rsa

注意:网上部分资料说IdentityFile为公钥文件名,经测试应为私钥文件名。

问题2 不支持密码认证

1
docker exec -it gitlab_web_1 /bin/bash -c 'vi /etc/ssh/sshd_config'

PasswordAuthentication yes 前的注释取消

步骤3 设置ssh端口

修改挂载的gitlab配置文件 sudo vi /gitlab/config/gitlab.rb

1
2
#修改服务端的ssh端口为宿主映射的端口
gitlab_rails['gitlab_shell_ssh_port'] = 822

修改完成后需要gitlab-ctl reconfigure使配置生效

参考链接

permission-denied-publickey

文章目录
  1. 1. gitlab ssh配置问题
    1. 1.1. 背景
    2. 1.2. 问题一 本地私钥找不到
    3. 1.3. 问题2 不支持密码认证
    4. 1.4. 步骤3 设置ssh端口
    5. 1.5. 参考链接